package com.service;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.biz.jdbc.ProductDao;
import com.engine.QueueInstance;
import com.engine.thread.LoadDataThread;
import com.engine.thread.SearchAPIThread;

/**
 * @author liuchao
 * @version $Id: SearchAPIListener.java,v 0.1 2012-9-21 下午9:37:02 liuchao Exp $
 */
public class SearchAPIListener implements ServletContextListener {

    protected Log                log = LogFactory.getLog(this.getClass());
    
    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        //直接关掉
        QueueInstance.getInstance().getSearchAPIExec().shutdownNow();
    }

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        SearchAPIThread searchAPIThread = new SearchAPIThread();
        QueueInstance.getInstance().getSearchAPIExec().submit(searchAPIThread);
        
        //
        ProductDao productDao = new ProductDao();
        LoadDataThread loadDateThread = new LoadDataThread( productDao  );
        QueueInstance.getInstance().getLoadUpdateExec().submit(loadDateThread);
    }

}
